import Vue from "vue";
import App from "./App";
import ElementUI, { Form } from "element-ui";
import VueI18n from "vue-i18n";
import "element-ui/lib/theme-chalk/index.css";
// Vue.use(ElementUI)//插件挂载  by guo 2019-12-30-11:39注释  下面重新引入了
Vue.use(VueI18n); //插件挂载
import VueRouter from "vue-router";
import store from "./store";
import Vuex from "vuex";
import routes from "./routes";
import "font-awesome/css/font-awesome.min.css";
import axios from "axios";
import {
  postForm,
  get,
  post,
  postJson,
  postLogin,
  postFormData,
  postMyForm,
  getToken,
  deleteList,
  put,
  getForm
} from "./api/http";
import isvalidPhone from "./commons/js/util"; //按需引入电话正则
import preview from "vue-photo-preview"; //图片预览插件
import "vue-photo-preview/dist/skin.css";
import Print from "@/plugs/print";
Vue.use(Print); // 注册
Vue.use(preview);
//引入公共css样式
import "../static/css/common.css";
//引入统一管理的URL 字符串
import ports from "./res/ports.js";
import Utils from "./commons/utils/common.js";
import Test from "../src/views/Test.vue"; //先引入模糊化组件

Vue.prototype.$Utils = Utils;

Vue.prototype.$axios = axios;
Vue.prototype.ports = ports;
Vue.config.productionTip = false;
Vue.prototype.$postForm = postForm;
Vue.prototype.$postJson = postJson;
Vue.prototype.$get = get;
Vue.prototype.$post = post;
Vue.prototype.$postLogin = postLogin;
Vue.prototype.$postFormData = postFormData;
Vue.prototype.$postMyForm = postMyForm;
Vue.prototype.$getToken = getToken;
Vue.prototype.$deleteList = deleteList;
Vue.prototype.$put = put;
Vue.prototype.$getForm = getForm;
Vue.prototype.$isvalidPhone = isvalidPhone; //电话号码正则
Vue.use(Vuex);
Vue.use(VueRouter);

/* 
  在main.js中全局引入武昌福利院后台项目的 iconfont.css  by guozhihang 2019-08-12 15:48 添加
*/
import "./assets/wuchangIconfont/iconfont.css";
/* 
  在main.js中全局引入life集团项目的 iconfont.css  by guozhihang 2020-01-19  16:33 添加
*/
import "./assets/lifeIconfont/iconfont.css";
/* 
  在main.js中全局引入社区版后台项目的 iconfont.css  by guozhihang 2019-08-12 15:48 添加
*/
import "./assets/communityIconfont/iconfont.css";

/* 
  在main.js中全局引入十堰项目的 iconfont.css   by guozhihang 2020-4-10 11:19 添加
*/
import "./assets/shiyanProjectIconfont/iconfont.css";

const router = new VueRouter({
  routes
});

const i18n = new VueI18n({
  // locale:'zh-CN',//语言标识  中文
  locale: "jp-JA", //语言标识  日文
  // this.$i18n.locale = 'en-US';//通过locale切换
  messages: {
    "zh-CN": require("./res/lang/zh"),
    "en-US": require("./res/lang/en"),
    "jp-JA": require("./res/lang/jp")
  }
});

//by guo 2019-12-30-11:38添加  在注册ElementUI时设置i18n的处理方法
Vue.use(ElementUI, {
  i18n: (key, value) => i18n.t(key, value) // 在注册Element时设置i18n的处理方法
});

axios.interceptors.response.use(
  function(response) {
    // Do something with response data
    if (response.headers != null) {
      // if (response.headers.get('renew-header')== 'true'){
      //   console.log('==========true');
      // }
    }
    return response;
  },
  function(error) {
    // Do something with response error
    //this.$message({message:"网络超时",type:"error"});//by guo 2020-3-19-13:48添加
    return Promise.reject(error);
  }
);

router.beforeEach((to, from, next) => {
  //NProgress.start();
  if (to.path == "/login") {
    sessionStorage.removeItem("user");
    //by guo 2019-11-20-23:07退出登录时清除store 清空tabList的值  清除activityTab   初始化再次登录的tab栏的数据
    sessionStorage.removeItem("store");
    store.state.tabList = [];
    sessionStorage.removeItem("activityTab");
  }
  //by guo 2020-1-6-11:34添加
  if (from.path == "/Schedule" || from.path == "/LeaveHospitalApproval") {
    sessionStorage.setItem("leaveHospitalFromPath", from.path);
  }
  if (from.path == "/Schedule" || from.path == "/changeFeeRootList") {
    sessionStorage.setItem("changeFeeShowFromPath", from.path);
  }
  let user = JSON.parse(sessionStorage.getItem("user"));
  if (!user && to.path != "/login" && to.path != "/login2") {
    // 判断是否是忘记密码 ，life忘记密码功能
    let jumpPsdForget = sessionStorage.getItem("jumpPsdForget");
    if (jumpPsdForget) {
      next();
    } else {
      next({ path: "/login" });
    }
  } else {
    next();
  }
});

//by guo 2019-11-20-11:57添加  全局重置滚动条的位置
router.afterEach((to, from, next) => {
  window.scrollTo(0, 0);
  // 或
  // window.scroll(0, 0);
});

Vue.prototype.$bus = new Vue(); //中央事件总线;

Vue.component("Test", Test); //全局注册视频模糊化处理组件

new Vue({
  // el: '#app',
  //template: '<App/>',
  router,
  i18n,
  store,
  // BaiduMap,
  //components: { App }
  render: h => h(App)
}).$mount("#app");
